# The purpose of this program is to assign the labels for the training examples
# currently, binary value for positive and negative value

from __future__ import division
from operator import itemgetter, attrgetter
import os
import sys
import math

# inputFileName = "/data3/obukai/the_new_trip_of_feature_generation/gov2ClearYourMindAndDoItAgain/Training_Set_2013_07_15_tfqAdded_tfcAdded_postingRankInDocAdd_postingRankInListAdd_percentageForPostingRankInDoc_percentageForPostingRankInList_WITH_headline_sortedBy_trecID.train"
# inputFileName = "/data3/obukai/the_new_trip_of_feature_generation/gov2ClearYourMindAndDoItAgain/Training_Set_2013_07_15_tfqAdded_tfcAdded_postingRankInDocAdd_postingRankInListAdd_percentageForPostingRankInDoc_percentageForPostingRankInList_WITH_headline_sortedBy_QueryID.train"
# inputFileName = "/data3/obukai/the_new_trip_of_feature_generation/gov2ClearYourMindAndDoItAgain/MLRelated/Model15/TrainingSetForFixingTheMissingTOPKResults20130715_tfqAdded_tfcAdded_postingRankInDocAdd_postingRankInListAdd_percentageForPostingRankInDoc_percentageForPostingRankInList_WITH_headline.train"
inputFileName = "/data3/obukai/the_new_trip_of_feature_generation/gov2ClearYourMindAndDoItAgain/MLRelated/Model17/TrainingSetForTOPKMissingResults20130719_tfqAdded_tfcAdded_postingRankInDocAdd_postingRankInListAdd_percentageForPostingRankInDoc_percentageForPostingRankInList_WITH_headline.train"
inputFileHandler = open(inputFileName,"r")

outputFileName = "/data3/obukai/the_new_trip_of_feature_generation/gov2ClearYourMindAndDoItAgain/MLRelated/Model17/TrainingSetForTOPKMissingResults20130719_tfqAdded_tfcAdded_postingRankInDocAdd_postingRankInListAdd_percentageForPostingRankInDoc_percentageForPostingRankInList_classLabelsAdded_WITH_headline.train"
# outputFileName = "/data3/obukai/the_new_trip_of_feature_generation/gov2ClearYourMindAndDoItAgain/Training_Set_2013_07_15_tfqAdded_tfcAdded_postingRankInDocAdd_postingRankInListAdd_percentageForPostingRankInDoc_percentageForPostingRankInList_classLabelsAdded_WITH_headline_sortedBy_trecID.train"
# outputFileName = "/data3/obukai/the_new_trip_of_feature_generation/gov2ClearYourMindAndDoItAgain/Training_Set_2013_07_15_tfqAdded_tfcAdded_postingRankInDocAdd_postingRankInListAdd_percentageForPostingRankInDoc_percentageForPostingRankInList_classLabelsAdded_WITH_headline_sortedBy_QueryID.train"
outputFileHandler = open(outputFileName,"w")

oldHeadline = inputFileHandler.readline()
newHeadline = oldHeadline.strip() + " " + "TOP10Label" + " " + "TOP100Label" + " " + "TOP1000Label" + " " + "TOP10000Label" + " " + "TOP100000Label" + "\n"

outputFileHandler.write(newHeadline)
for line in inputFileHandler.readlines():
    lineElements = line.strip().split(" ")
    rankInResultListInIntFormat = int(lineElements[12])
    TOP10Label = "False"
    TOP100Label = "False"
    TOP1000Label = "False"
    TOP10000Label = "False"
    TOP100000Label = "False"
    
    if rankInResultListInIntFormat >= 1 and rankInResultListInIntFormat <= 10:
        TOP10Label = "True"
    if rankInResultListInIntFormat >= 1 and rankInResultListInIntFormat <= 100:
        TOP100Label = "True"
    if rankInResultListInIntFormat >= 1 and rankInResultListInIntFormat <= 1000:
        TOP1000Label = "True"
    if rankInResultListInIntFormat >= 1 and rankInResultListInIntFormat <= 10000:
        TOP10000Label = "True"
    if rankInResultListInIntFormat >= 1 and rankInResultListInIntFormat <= 100000:
        TOP100000Label = "True"        
    
    outputFileHandler.write(line.strip() + " " + TOP10Label + " " + TOP100Label + " " + TOP1000Label + " " + TOP10000Label + " " + TOP100000Label + "\n")

print "Overall Processing Statistics:"
print "inputFileName:",inputFileName
print "outputFileName:",outputFileName
inputFileHandler.close()
outputFileHandler.close()


